<?php

class MedalleroController extends Controller
{
	public function actionIndex11()
	{
		Yii::app()->theme='resultados';
		Yii::app()->name='MEDALLERO - MANTA 2011';	
		
		$connection = Yii::app()->db;
		$command = $connection->createCommand("
		SELECT gp.pais_id,gp.pais_nombre,sum(grm.grid_oro) as oro,sum(grm.grid_plata) as plata,sum(grm.grid_bronce) as bronce,
sum(grm.grid_oro)*10000 +sum(grm.grid_plata)*75+sum(grm.grid_bronce) as orden

		    FROM grid_r_medallas grm 
        
        inner join grid_r_entidad gre 
        on gre.grid_entidad_id = grm.grid_entidad_id
        
        inner join grid_pais gp
        on gp.pais_id = gre.grid_pais_id
        group by gp.pais_id,gp.pais_nombre
        order by orden,pais_id desc");

		$dataReader = $command->query();
		
		$rows=$dataReader->readAll();
		
		$orden = array_reverse($rows);
		
		
		$this->renderPartial('indexbk',array('orden'=>$orden));
	}
	
	public function actionIndex()
	{
		Yii::app()->theme='resultados';
		Yii::app()->name='MEDALLERO - MANTA 2011';	
		
		$connection = Yii::app()->db;
		$command = $connection->createCommand("
		SELECT gp.pais_id,gp.pais_nombre,sum(grm.grid_oro) as oro,sum(grm.grid_plata) as plata,sum(grm.grid_bronce) as bronce,
sum(grm.grid_oro)*10000 +sum(grm.grid_plata)*75+sum(grm.grid_bronce) as orden

		    FROM grid_r_medallas grm 
        
        inner join grid_r_entidad gre 
        on gre.grid_entidad_id = grm.grid_entidad_id
        
        inner join grid_pais gp
        on gp.pais_id = gre.grid_pais_id
        group by gp.pais_id,gp.pais_nombre
        order by orden,pais_id desc");

		$dataReader = $command->query();
		
		$rows=$dataReader->readAll();
		
		$orden =array_reverse($rows);
		
		
		$this->render('index',array('orden'=>$orden));
	}

	public function actionPais()
	{
		Yii::app()->theme='resultados';
		Yii::app()->name='MEDALLERO PAIS- MANTA 2011';	
		
		$pais = Yii::app()->request->getQuery('pais');
		if(!empty($pais))
		{
			$orden = DeporteActividad::model()->findAll(array('order'=>'deporte_actividad_descripcion'));
			$this->render('pais',array('orden'=>$orden,'pais'=>$pais));
		}
		else
		{
			Yii::app()->name='MEDALLERO - MANTA 2011';	
			$orden = RMedallero::model()->findAll(array('order'=>'orden','condition'=>'tipo=:x', 'params'=>array(':x'=>'MEDALLERO')));		
			$this->render('index');	
		}
	}
	
	
	public function actionDeporte()
	{
	Yii::app()->theme='resultados';
		Yii::app()->name='MEDALLERO PAIS- MANTA 2011';	
		
		$deporte = Yii::app()->request->getQuery('deporte');
		if(!empty($deporte))
		{
			$connection = Yii::app()->db;
		$command = $connection->createCommand("
		SELECT gp.pais_id,gp.pais_nombre,sum(grm.grid_oro) as oro,sum(grm.grid_plata) as plata,sum(grm.grid_bronce) as bronce,
sum(grm.grid_oro)*10000 +sum(grm.grid_plata)*75+sum(grm.grid_bronce) as orden

		    FROM grid_r_medallas grm 
        
        inner join grid_r_entidad gre 
        on gre.grid_entidad_id = grm.grid_entidad_id
        
        inner join grid_pais gp
        on gp.pais_id = gre.grid_pais_id
                    
        where gre.grid_deporte_actividad_id=$deporte
        
        group by pais_id,pais_nombre
        order by orden,pais_id desc");

		$dataReader = $command->query();
		
		$rows=$dataReader->readAll();
	
		$orden = array_reverse($rows);
			
			
		$this->render('deporte',array('orden'=>$orden,'deporte'=>$deporte));
		
		}
		else
		{
			$this->redirect('index');
		}
	}
	
	public function actionDeporte11()
	{
	Yii::app()->theme='resultados';
		Yii::app()->name='MEDALLERO PAIS- MANTA 2011';	
		
		$deporte = Yii::app()->request->getQuery('deporte');
		if(!empty($deporte))
		{
			$connection = Yii::app()->db;
		$command = $connection->createCommand("
		SELECT gp.pais_id,gp.pais_nombre,sum(grm.grid_oro) as oro,sum(grm.grid_plata) as plata,sum(grm.grid_bronce) as bronce,
sum(grm.grid_oro)*10000 +sum(grm.grid_plata)*75+sum(grm.grid_bronce) as orden

		    FROM grid_r_medallas grm 
        
        inner join grid_r_entidad gre 
        on gre.grid_entidad_id = grm.grid_entidad_id
        
        inner join grid_pais gp
        on gp.pais_id = gre.grid_pais_id
                    
        where gre.grid_deporte_actividad_id=$deporte
        
        group by pais_id,pais_nombre
        order by orden,pais_id desc");

		$dataReader = $command->query();
		
		$rows=$dataReader->readAll();
	
		$orden = array_reverse($rows);
			
			
		$this->renderPartial('deportebk',array('orden'=>$orden,'deporte'=>$deporte));
		
		}
		else
		{
			$this->redirect('index');
		}
	}
	
	public function actionDeportes()
	{
		Yii::app()->theme='resultados';
		Yii::app()->name='DEPORTES - MANTA 2011';
		$this->render('deportes');
	}
	
	public function actionMedallistas()
	{
		Yii::app()->theme='resultados';
		Yii::app()->name='MEDALLISTAS - MANTA 2011';
		
		$pais = Yii::app()->request->getQuery('pais');
		$deporte = Yii::app()->request->getQuery('deporte');	
		
		if(!empty($pais)&&!empty($deporte))
		{
		$connection = Yii::app()->db;	
		$command = $connection->createCommand("
		SELECT gin.inscripcion_nominal_id,gin.inscripcion_nominal_foto,gpa.pais_nombre,gp.persona_nombres_apellidos,gre.grid_genero,grpr.grid_programa_descripcion,grm.grid_tipo_medalla,gpa.pais_id,gre.grid_grupo          
        FROM grid_r_medallas grm 
        
        inner join grid_r_entidad gre 
        on gre.grid_entidad_id = grm.grid_entidad_id
        
        inner join grid_r_detalle_entidad grde
        on grde.grid_entidad_id = gre.grid_entidad_id
        
        inner join grid_persona gp
        on gp.persona_id = grde.grid_persona_id
        
        inner join grid_inscripcion_nominal gin
        on gin.inscripcion_nominal_persona = gp.persona_id
        
        inner join grid_pais gpa
        on gpa.pais_id = gre.grid_pais_id
                    
        inner join grid_r_programa grpr
        on grpr.grid_programa_id=grm.grid_programa_id
                    
        where gre.grid_deporte_actividad_id=$deporte and gpa.pais_id=$pais
        
        order by grid_programa_descripcion,grid_genero,persona_nombres_apellidos");

		$dataReader = $command->query();
		
		$rows=$dataReader->readAll();
		
		$this->render('medallistas',array('personas'=>$rows,'pais'=>$pais,'deporte'=>$deporte));
		}
		else 
		{			
			Yii::app()->name='MEDALLERO - MANTA 2011';			
			$this->render('index');	
		}
		
		
	}
	
	public function actionPaises()
	{
		Yii::app()->theme='resultados';
		Yii::app()->name='PAISES PARTICIPANTES - MANTA 2011';	
		$this->render('paises');
	}
	// Uncomment the following methods and override them if needed
	/*
	public function filters()
	{
		// return the filter configuration for this controller, e.g.:
		return array(
			'inlineFilterName',
			array(
				'class'=>'path.to.FilterClass',
				'propertyName'=>'propertyValue',
			),
		);
	}

	public function actions()
	{
		// return external action classes, e.g.:
		return array(
			'action1'=>'path.to.ActionClass',
			'action2'=>array(
				'class'=>'path.to.AnotherActionClass',
				'propertyName'=>'propertyValue',
			),
		);
	}
	*/
}